<!-- template~html -->
<template>
    <nav class="navbar navbar-expand-lg navbar-dark" style="z-index: 2;background-color: rgba(99, 143, 238, 0.5);border: 1px solid rgb(133, 138, 143);">
        <div class="container">
          <img src="../assets/images/kob.png" alt="" style="width: 45px; height: 45px;margin-right: 20px;" class="img-fluid">
          <!-- router-link ~a标签，跳转不用刷新页面 :to="{name:?}"-->
          <router-link :class="route_name=='pk'? 'navbar-brand active' : 'navbar-brand' " :to="{name:'home'}" style="font-weight: bold;">
             Snake Of Bots
          </router-link>
          <button class="navbar-toggler btn-info" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarText">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                <li class="nav-item">
                  <router-link :class="route_name == 'pk_index'? 'nav-link active' :'nav-link'" :to="{name:'pk_index'}">pk</router-link>
                </li>
                <li class="nav-item">
                  <router-link :class="route_name == 'record_index'? 'nav-link active' : 'nav-link'" :to="{name:'record_index'}">对局列表</router-link>
                </li>
                <li class="nav-item">
                  <router-link :class="route_name == 'ranklist_index' ? 'nav-link active' :'nav-link'" :to="{name:'ranklist_index'}">排行榜</router-link>
                </li>
              </ul>
            <ul class="navbar-nav">
                <li v-if="$store.state.user.isLogin" class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                      <img :src="$store.state.user.photo" alt="" style="width: 35px; height: 35px;border-radius: 50%;">
                      <!-- {{$store.state.user.username}} -->
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                      <li><router-link class="dropdown-item" :to="{name:'user_index'}">我的Bots</router-link></li>
                      <li><a class="dropdown-item" href="#" @click="logout">退出</a></li>
                    </ul>
                </li>
                <li v-else class="nav-item link">
                  <router-link to="/user/account/login" class="nav-link" style="float: left;">登录</router-link >
                  <router-link to="/user/account/register" class="nav-link" style="float: left;">注册</router-link >
                </li>
            </ul>
          </div>
        </div>
      </nav>
</template>
    
<script>
  import { computed } from "vue";
  import { useRoute } from "vue-router";
  import {useStore} from 'vuex'
  export default{
    setup(){
      const route = useRoute();
      const store = useStore();
      let route_name = computed(() => route.name)
      let logout = function(){
        store.commit('Logout')
        localStorage.removeItem('jwt_token')
      }
      return{
        route_name,
        logout
      }
    }
  }
</script>

<style scoped>
</style> 